package com.jy.rhin.application.basic;


import com.jy.rhin.application.basic.event.PublishMessageEvent;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDto;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: lww
 * @Date: 2022/7/6 10:01
 */
@Component
public class NotificationEventHandler {

    @Resource
    NotificationService notificationService;

    /**
     * 处理需要通知订阅者的消息并通知订阅者
     */
    @EventListener
    public void publishMessageEventHandler(PublishMessageEvent messageEvent) {
        List<PublishMessageDto> publishMessageList = messageEvent.getPublishMessageList();
        for (PublishMessageDto publishMessageDto : publishMessageList) {
            notificationService.notifySubscriber(publishMessageDto);
        }
    }

}
